<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>可选课程 - 学生管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
    <style>
        .sidebar {
            min-height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.8);
            padding: 12px 20px;
            border-radius: 8px;
            margin: 5px 10px;
            transition: all 0.3s;
        }
        .sidebar .nav-link:hover,
        .sidebar .nav-link.active {
            color: white;
            background: rgba(255, 255, 255, 0.2);
            transform: translateX(5px);
        }
        .main-content {
            background: #f8f9fa;
            min-height: 100vh;
        }
        .course-card {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            transition: transform 0.3s;
            height: 100%;
        }
        .course-card:hover {
            transform: translateY(-5px);
        }
        .course-header {
            border-bottom: 1px solid #eee;
            padding-bottom: 1rem;
            margin-bottom: 1rem;
        }
        .course-title {
            color: #333;
            font-weight: 600;
            margin-bottom: 0.5rem;
        }
        .course-code {
            color: #666;
            font-size: 0.9rem;
        }
        .course-info {
            margin-bottom: 1rem;
        }
        .info-item {
            display: flex;
            align-items: center;
            margin-bottom: 0.5rem;
            color: #666;
            font-size: 0.9rem;
        }
        .info-item i {
            margin-right: 0.5rem;
            width: 16px;
        }
        .capacity-bar {
            background: #e9ecef;
            border-radius: 10px;
            height: 8px;
            margin: 0.5rem 0;
        }
        .capacity-fill {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 10px;
            height: 100%;
            transition: width 0.3s;
        }
        .btn-enroll {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            color: white;
            padding: 8px 20px;
            border-radius: 20px;
            font-weight: 500;
            transition: all 0.3s;
        }
        .btn-enroll:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
            color: white;
        }
        .btn-enroll:disabled {
            background: #6c757d;
            transform: none;
            box-shadow: none;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-3 col-lg-2 px-0">
                <div class="sidebar">
                    <div class="p-3">
                        <h4 class="text-white mb-4">
                            <i class="bi bi-person-circle me-2"></i>学生中心
                        </h4>
                        <nav class="nav flex-column">
                            <a class="nav-link" href="/student/dashboard">
                                <i class="bi bi-house-door me-2"></i>首页
                            </a>
                            <a class="nav-link active" href="/student/courses">
                                <i class="bi bi-book me-2"></i>可选课程
                            </a>
                            <a class="nav-link" href="/student/my-courses">
                                <i class="bi bi-journal-bookmark me-2"></i>我的课程
                            </a>
                            <a class="nav-link" href="/student/schedule">
                                <i class="bi bi-calendar3 me-2"></i>我的课表
                            </a>
                            <a class="nav-link" href="/student/profile">
                                <i class="bi bi-person me-2"></i>个人信息
                            </a>
                            <hr class="text-white-50">
                            <a class="nav-link" href="/logout">
                                <i class="bi bi-box-arrow-right me-2"></i>退出登录
                            </a>
                        </nav>
                    </div>
                </div>
            </div>
            
            <!-- 主内容区 -->
            <div class="col-md-9 col-lg-10">
                <div class="main-content">
                    <div class="p-4">
                        <div class="d-flex justify-content-between align-items-center mb-4">
                            <h2 class="mb-0">可选课程</h2>
                            <div class="d-flex gap-2">
                                <input type="text" class="form-control" placeholder="搜索课程..." style="width: 300px;">
                                <button class="btn btn-outline-primary">
                                    <i class="bi bi-search"></i>
                                </button>
                            </div>
                        </div>
                        
                        <!-- 课程列表 -->
                        <div class="row g-4">
                            <div class="col-lg-6" th:each="course : ${courses}">
                                <div class="course-card">
                                    <div class="course-header">
                                        <h5 class="course-title" th:text="${course.name}">Java程序设计</h5>
                                        <span class="course-code" th:text="${course.courseCode}">CS101</span>
                                    </div>
                                    
                                    <div class="course-info">
                                        <div class="info-item">
                                            <i class="bi bi-person-badge"></i>
                                            <span>教师：<span th:text="${course.teacher?.name}">王教授</span></span>
                                        </div>
                                        <div class="info-item">
                                            <i class="bi bi-award"></i>
                                            <span>学分：<span th:text="${course.credits}">3</span></span>
                                        </div>
                                        <div class="info-item">
                                            <i class="bi bi-info-circle"></i>
                                            <span th:text="${course.description}">Java编程基础课程</span>
                                        </div>
                                        
                                        <!-- 容量信息 -->
                                        <div class="mt-3">
                                            <div class="d-flex justify-content-between align-items-center mb-1">
                                                <small class="text-muted">选课情况</small>
                                                <small class="text-muted">
                                                    <span th:text="${course.selectedCount}">0</span> / 
                                                    <span th:text="${course.capacity}">50</span>
                                                </small>
                                            </div>
                                            <div class="capacity-bar">
                                                <div class="capacity-fill" 
                                                     th:style="'width: ' + ${#numbers.formatDecimal(course.selectedCount / course.capacity * 100, 1, 1)} + '%'">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="d-flex justify-content-between align-items-center">
                                        <div>
                                            <span th:if="${course.selectedCount < course.capacity}" 
                                                  class="badge bg-success">可选课</span>
                                            <span th:if="${course.selectedCount >= course.capacity}" 
                                                  class="badge bg-danger">已满员</span>
                                        </div>
                                        <form th:action="@{/student/enroll/{id}(id=${course.id})}" method="post" style="display: inline;">
                                            <button type="submit" class="btn btn-enroll" 
                                                    th:disabled="${course.selectedCount >= course.capacity}">
                                                <i class="bi bi-plus-circle me-1"></i>选课
                                            </button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 空状态 -->
                        <div th:if="${#lists.isEmpty(courses)}" class="text-center py-5">
                            <i class="bi bi-book" style="font-size: 4rem; color: #ccc;"></i>
                            <h4 class="text-muted mt-3">暂无可选课程</h4>
                            <p class="text-muted">当前没有可选的课程，请稍后再试。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
